#ifndef MULTIDRESSMAKER_H
#define MULTIDRESSMAKER_H
#include "tools/Pyscript.h"
#include "tools/Gadget.h"

class MultidressMaker : public QObject, public QRunnable{

    Q_OBJECT

public:
    explicit MultidressMaker(QMap<ThreadPoint, NT::THREAD_STATE> &_pool_thread_,
                             QMap<QString, QString> &_pool_chars_,
                             QMap<QString, QList<qint64>> &_pool_stint_,
                             QSqlDatabase *db){
        pool_thread = &_pool_thread_;
        pool_chars = &_pool_chars_;
        pool_stint = &_pool_stint_;
        SqlQuery = QSqlQuery(*db);
    }

    void run(){
        QMutex Lock;
        Lock.lock();
        (*pool_thread)[ThreadPoint::MULTI_CROP] = NT::THREAD_RECOVER;
        QString byteString=NULL;
        QList<qint64> clipsize = (*pool_stint)["clipsize_send"];
        QList<qint64> cliprect = (*pool_stint)["clipping_send"];
        if (!clipsize.isEmpty() && !cliprect.isEmpty())
        {
            PPScriptExec::pyScript_ImageByteDressMaker("outer_script",
                                                       "pixmapCrop",
                                                       (*pool_chars)["acadd-temporary-head"].toStdString().data(),
                                                       clipsize,
                                                       cliprect,
                                                       byteString);
            QString ac_head_upsql = QString("UPDATE user_datum SET ac_head = %1 "
                                    "WHERE ac_id = '%2'").arg(byteString,
                                                             (*pool_chars)["ac-accept-name"]);
            SqlQuery.exec(ac_head_upsql);
            if (!byteString.isEmpty()) emit headtailor_infosend(byteString);
        }
        Lock.unlock();
        (*pool_thread)[ThreadPoint::MULTI_CROP] = NT::THREAD_IDLEABOUT;
    }

private:
    Extend definfc;
    QSqlQuery SqlQuery;
    QMap<QString, QString> *pool_chars;
    QMap<QString, QList<qint64>> *pool_stint;
    QMap<ThreadPoint, NT::THREAD_STATE> *pool_thread;

signals:
    void headtailor_infosend(QString);
};



#endif // MULTIDRESSMAKER_H
